import { Sprite } from "@/sprites/Sprite.js";
import { config } from "@/managers/ConfigManager.js";
import { ImageManager } from "@/managers/ImageManager.js";
export class Sprite_Icon extends Sprite{
    constructor(){
        super();
        this.iconIndex=0;
        this.visible=false;

        this.isReady=false;
        ImageManager.loadSystem('IconSet').then(source=>{
            this.source=source;
            this.isReady=true;
            if(this.iconIndex>0){
                this._setIndex(this.iconIndex);
            }else{
                this.setFrame(0,0,0,0);
            }
        });
    }

    setIndex(index){
        if(this.iconIndex!=index){
            this.iconIndex=index;
            if(this.isReady){
                this._setIndex(this.iconIndex);
            }
        }
    }

    _setIndex(index){
        if(index<=0){
            this.visible=false;
            this.setFrame(0,0,0,0);
            return;
        }
        this.visible=true;
        let x=index%16;
        let y=(index-x)/16;
        let size=config.iconSize;
        this.setFrame(x*size,y*size,size,size);
    }
}